package com.usian.user.controller;

import com.usian.user.service.IChatStreamAssistant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@Slf4j
@RestController
@RequestMapping("/user/streamAssistant")
public class TestController {

    @Autowired
    @Qualifier("chatStreamAssistant")
    private IChatStreamAssistant streamAssistant;

    @GetMapping(value = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> stream(@RequestParam(value = "message", defaultValue = "Hello") String message){
        Flux<String> stringFlux = streamAssistant.chat(message);
        log.info("Received message (GET): {}", message); // 打印日志
        return stringFlux;
    }


}
